package cn.shuto.liferay.plugin.chart.service.model.impl;

import cn.shuto.liferay.plugin.chart.service.model.DataSourceCfg;

import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import java.util.Date;

/**
 * The cache model class for representing DataSourceCfg in entity cache.
 *
 * @author shixw
 * @see DataSourceCfg
 * @generated
 */
public class DataSourceCfgCacheModel implements CacheModel<DataSourceCfg>,
    Externalizable {
    public String uuid;
    public long dataSourceId;
    public long groupId;
    public long companyId;
    public long userId;
    public String userName;
    public long createDate;
    public long modifiedDate;
    public String name;
    public String description;
    public String driver;
    public String connUrl;
    public String dbusername;
    public String dbpassword;

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(29);

        sb.append("{uuid=");
        sb.append(uuid);
        sb.append(", dataSourceId=");
        sb.append(dataSourceId);
        sb.append(", groupId=");
        sb.append(groupId);
        sb.append(", companyId=");
        sb.append(companyId);
        sb.append(", userId=");
        sb.append(userId);
        sb.append(", userName=");
        sb.append(userName);
        sb.append(", createDate=");
        sb.append(createDate);
        sb.append(", modifiedDate=");
        sb.append(modifiedDate);
        sb.append(", name=");
        sb.append(name);
        sb.append(", description=");
        sb.append(description);
        sb.append(", driver=");
        sb.append(driver);
        sb.append(", connUrl=");
        sb.append(connUrl);
        sb.append(", dbusername=");
        sb.append(dbusername);
        sb.append(", dbpassword=");
        sb.append(dbpassword);
        sb.append("}");

        return sb.toString();
    }

    @Override
    public DataSourceCfg toEntityModel() {
        DataSourceCfgImpl dataSourceCfgImpl = new DataSourceCfgImpl();

        if (uuid == null) {
            dataSourceCfgImpl.setUuid(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setUuid(uuid);
        }

        dataSourceCfgImpl.setDataSourceId(dataSourceId);
        dataSourceCfgImpl.setGroupId(groupId);
        dataSourceCfgImpl.setCompanyId(companyId);
        dataSourceCfgImpl.setUserId(userId);

        if (userName == null) {
            dataSourceCfgImpl.setUserName(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setUserName(userName);
        }

        if (createDate == Long.MIN_VALUE) {
            dataSourceCfgImpl.setCreateDate(null);
        } else {
            dataSourceCfgImpl.setCreateDate(new Date(createDate));
        }

        if (modifiedDate == Long.MIN_VALUE) {
            dataSourceCfgImpl.setModifiedDate(null);
        } else {
            dataSourceCfgImpl.setModifiedDate(new Date(modifiedDate));
        }

        if (name == null) {
            dataSourceCfgImpl.setName(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setName(name);
        }

        if (description == null) {
            dataSourceCfgImpl.setDescription(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setDescription(description);
        }

        if (driver == null) {
            dataSourceCfgImpl.setDriver(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setDriver(driver);
        }

        if (connUrl == null) {
            dataSourceCfgImpl.setConnUrl(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setConnUrl(connUrl);
        }

        if (dbusername == null) {
            dataSourceCfgImpl.setDbusername(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setDbusername(dbusername);
        }

        if (dbpassword == null) {
            dataSourceCfgImpl.setDbpassword(StringPool.BLANK);
        } else {
            dataSourceCfgImpl.setDbpassword(dbpassword);
        }

        dataSourceCfgImpl.resetOriginalValues();

        return dataSourceCfgImpl;
    }

    @Override
    public void readExternal(ObjectInput objectInput) throws IOException {
        uuid = objectInput.readUTF();
        dataSourceId = objectInput.readLong();
        groupId = objectInput.readLong();
        companyId = objectInput.readLong();
        userId = objectInput.readLong();
        userName = objectInput.readUTF();
        createDate = objectInput.readLong();
        modifiedDate = objectInput.readLong();
        name = objectInput.readUTF();
        description = objectInput.readUTF();
        driver = objectInput.readUTF();
        connUrl = objectInput.readUTF();
        dbusername = objectInput.readUTF();
        dbpassword = objectInput.readUTF();
    }

    @Override
    public void writeExternal(ObjectOutput objectOutput)
        throws IOException {
        if (uuid == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(uuid);
        }

        objectOutput.writeLong(dataSourceId);
        objectOutput.writeLong(groupId);
        objectOutput.writeLong(companyId);
        objectOutput.writeLong(userId);

        if (userName == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(userName);
        }

        objectOutput.writeLong(createDate);
        objectOutput.writeLong(modifiedDate);

        if (name == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(name);
        }

        if (description == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(description);
        }

        if (driver == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(driver);
        }

        if (connUrl == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(connUrl);
        }

        if (dbusername == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(dbusername);
        }

        if (dbpassword == null) {
            objectOutput.writeUTF(StringPool.BLANK);
        } else {
            objectOutput.writeUTF(dbpassword);
        }
    }
}
